import request from '@/utils/request'
export function create(data){
    return request({
        url: '/org',
        method: 'post',
        data
    })
}

export function update(data){
    return request({
        url: '/org',
        method: 'put',
        data
    })
}

export function del(id){
    return request({
        url: '/org/'+id,
        method: 'delete'
    })
}

// 根据id或者对象
export function selectOne(id){
    return request({
        url: '/org/'+id,
        method: 'get'
    })

}
export function page(query) {
    return request({
        url: '/org/page',
        method: 'get',
        params: query
    })
}

export function all() {
    return request({
        url: '/org/all',
        method: 'get'
    })
}

export function iteratorSearchOrgCode(element,orgCode){
    let result = false
    if(element.orgCode == orgCode){
        result =  true
    }else {
        if(element.children == null || element.children.length ==0){
            return false
        }
        element.children.some(element => {
            const iteratorResult = iteratorSearchOrgCode(element,orgCode)
            if(iteratorResult){
                result =  true 
                return true
            }
        });
    }
    return result
}

export function iteratorSearchOrgName(element,orgName){
    let result = false
    if(element.orgName == orgName){
        return true
    }else {
        if(element.children == null || element.children.length ==0){
            return false
        }
        element.children.some(element => {
            const iteratorResult = iteratorSearchOrgName(element,orgName)
            if(iteratorResult){
                result =  true 
                return true
            } 
        });
    }
    return result
}